﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1Tests
{
    [TestClass]
    public class RefOUt什么鬼
    {
        class Person
        {
            public string Name { get; set; }
            public Person(string name = "")
            {
                Name = name;
            }
        }
        void Change(Person p)
        {
            p.Name = "lishi";
            p = new Person("abcd");//重新实例化这种并不能修改数据
            p = new Person();
            p.Name = "khhhkg";
        }
        void Change(Person p, string name)
        {
            p.Name = name;
        }
        void Change(ref Person p)
        {
            p = new Person("www");
        }
        [TestMethod]
        public void Test()
        {
            Person p = new Person("张三");
            Change(p);
            Console.WriteLine(p.Name); //输出的是张三 并不是李四

            Change(p, "李四");
            Console.WriteLine(p.Name);//输出的是李四

            Change(ref p);
            Console.WriteLine(p.Name); //输出的是王五 


            int i = 1, j = 10;
            var result = RefValue(i, ref j);
            Console.WriteLine("i:{0},j:{1},result:{2}", i, j, result);

            result = OutValue(i, out j);
            Console.WriteLine("i:{0},j:{1},result:{2}", i, j, result);
        }
        int RefValue(int i, ref int j)
        {
            //这里就想说j还是值类型,不管你做了什么,k并不能和他保持改变
            int k = j;
            j = 222;
            return i + k;
        }


        int OutValue(int i, out int j)
        {
            j = 10;
            int k = j;
            j = 222;
            return i + k;
        }
    }
}
